Here we add Sliding Transition to the Image View.
This means that when Image is added to the Screen it will not just suddenly appear at its position.
After pressing the Button Image appears on the left and starts its Animation toward the center of the Screen.
And when we remove it, it will disappear from the Screen by sliding to the right .
With Transition
struct ContentView: View {
@State private var show = true
var body: some View {
VStack {
Button("BUTTON") { self.show.toggle() }
if (show) {
Image("Table").resizable().frame(width: 200, height: 200)
.transition(AnyTransition.slide)
.animation(.default)
}
}
}
}
Initially Image is not shown After pressing the Button Image appears on the left
Then it slides into position at the center of the Screen Image leaves the Screen by sliding to the right
Image is removed from the Screen